No, they released it after the polls were no longer close, when Clinton had pulled back out to a 7 pt lead or so.
I have no doubt that the person who sent the tape to the Times did it to hurt Trump, just as I have no doubt that the Russians who hacked the DNC did it to hurt Clinton. And, yes, the State Department is confident it was the Russians, and yes, Trump did know about this before the first debate--he had received the intelligence briefings. When he claimed there was no reason to think it was the Russians during both debates, he was flat-out lying.
the Clinton foundation/clinton campaign/etc paid a lot for it.
The Clinton Foundation is not the Clinton campaign. You're thinking of Trump who uses money from his foundation to purchase personal things for himself and to settle leagal bills and to bribe Florida officials.